package com.yanxibao.controller;

import com.yanxibao.bean.UmInfo;
import com.yanxibao.common.Result;
import com.yanxibao.dto.PageQueryDTO;
import com.yanxibao.service.UmInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 院校专业详情;(_umInfo)表控制层
 *
 * @author kongke
 * @date 2023/11/16
 */
@Api(tags = "院校专业详情对象功能接口")
@RestController
@CrossOrigin
@RequestMapping("/UmInfo")
public class UmInfoController {

    @Resource
    private UmInfoService umInfoService;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     */
    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/getById/{id}")
    public Result<UmInfo> queryById(@PathVariable Integer id) {
        return umInfoService.queryById(id);
    }

    /**
     * 分页查询
     */
    @ApiOperation("分页查询")
    @PostMapping("/getPage")
    @ResponseBody
    public Result<PageQueryDTO<UmInfo>> pageQuery(@RequestParam("current") Integer current,
                                                  @RequestParam("size") Integer size,
                                                  @RequestBody UmInfo umInfo) {

        return umInfoService.pageQuery(umInfo, current, size);
    }

    /**
     * 新增数据
     *
     * @param umInfo 实例对象
     */
    @ApiOperation("新增数据")
    @PostMapping("/add")
    public Result<UmInfo> add(@RequestBody UmInfo umInfo) {
        return umInfoService.insert(umInfo);
    }

    /**
     * 更新数据
     *
     * @param umInfo 实例对象
     */
    @ApiOperation("更新数据")
    @PutMapping("/update")
    public Result<UmInfo> update(@RequestBody UmInfo umInfo) {
        return umInfoService.update(umInfo);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     */
    @ApiOperation("通过主键删除数据")
    @DeleteMapping("/del/{id}")
    public Result<Boolean> deleteById(@PathVariable Integer id) {
        return umInfoService.deleteById(id);
    }
}